import axios from 'axios';
import api from './api'

const service = axios.create({
    // process.env.NODE_ENV === 'development' 来判断是否开发环境
    baseURL: api,
    //baseURL: '',
    timeout: 10000
})

service.interceptors.request.use(config => {
    let newConfig = config;
    newConfig = {
        ...config,
        headers: {
            token: localStorage.getItem('token') || '',
        },
    };
    return newConfig;
}, error => {
    console.log(error);
    return Promise.reject();
})

service.interceptors.response.use(response => {
    if (response.status === 200) {
        return response.data;
    } else {
        Promise.reject();
    }
}, error => {
    console.log(error);
    return Promise.reject();
})

export default service;